package com.mao.crowd.service.impl;

import com.mao.crowd.entity.po.MemberPO;
import com.mao.crowd.entity.po.MemberPOExample;
import com.mao.crowd.mapper.MemberPOMapper;
import com.mao.crowd.service.api.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author maomeng
 * @create 2021-06-17- 16:41
 */
@Transactional(readOnly = true)
@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberPOMapper memberPOMapper;

    @Override
    public MemberPO getMemberPOByLoginAcct(String loginacct) {
        // 还是之前ssm阶段的内部查询流程
        MemberPOExample memberPOExample = new MemberPOExample();
        MemberPOExample.Criteria criteria = memberPOExample.createCriteria();
        criteria.andLoginacctEqualTo(loginacct);

        List<MemberPO> memberPOList = memberPOMapper.selectByExample(memberPOExample);
        if(memberPOList == null || memberPOList.size() == 0){
            return null;
        }
        return memberPOList.get(0);
    }

    // 取消只读,设置传播行为,注解回滚
    @Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = Exception.class,readOnly = false)
    @Override
    public void saveMember(MemberPO memberPO) {
        memberPOMapper.insertSelective(memberPO);
    }
}
